import * as api from '../api'
export default (state,action)=>{
    state=state || {data:[],foods:[],articles:[],house:[],specials:[]}
    switch(action.type){
        case 'GREATLIFES':
            return {...state,data:action.data};
        case 'FOODS':
            return {...state,foods:action.foods};
        case 'ARTICLES':
            return {...state,articles:action.articles};
        case 'HOUSE':
            return {...state,house:action.house};
        case 'SPECIALS':
            return {...state,specials:action.specials};        
        default:
            return state
    }
}
// 获取生活表
export const greatLifes=()=>(dispatch)=>{
    fetch(api.GREATLIFES).then(response=>response.json()).then(requlst=>{
        dispatch({type:'GREATLIFES',data:requlst.data})
    })
}
// 获取精彩生活
export const getFoods=()=>(dispatch)=>{
    fetch(api.FOODS).then(response=>response.json()).then(requlst=>{
        dispatch({type:'FOODS',foods:requlst.data})
    })
}
// 获取生活用品
export const getArticles=()=>(dispatch)=>{
    fetch(api.ARTICLES).then(response=>response.json()).then(requlst=>{
        dispatch({type:'ARTICLES',articles:requlst.data})
    })
}
// 获取生活家具
export const getHouse=()=>(dispatch)=>{
    fetch(api.HOUSE).then(response=>response.json()).then(requlst=>{
        dispatch({type:'HOUSE',house:requlst.data})
    })
}
// 获取特卖专区
export const getSpecials=()=>(dispatch)=>{
    fetch(api.SPECIALS).then(response=>response.json()).then(requlst=>{
        dispatch({type:'SPECIALS',specials:requlst.data})
    })
}